feat/ns http#20
Merged
Merged
Conversation
Introduces the `ns_http` module, wrapping Rust's `reqwest` crate to provide a modern, synchronous HTTP API to C without the complexity and callback management of `libcurl`. Key additions: - Implemented `ns_http_get` and `ns_http_post` for standard web requests. - Added `ns_http_response` struct to cleanly capture HTTP status codes and pack the response body directly into memory-safe SSO `ns_string` structs. - Introduced the `ns_autohttp` macro, leveraging the GCC/Clang cleanup attribute to provide RAII, automatically freeing HTTP response buffers when they fall out of scope. - Created `18_http.c` example demonstrating fetching data and pushing JSON payloads. - Registered `ns_http` crate in the workspace and added `reqwest` dependency. Signed-off-by: Vaishnav Sabari Girish <vaishnav.sabari.girish@gmail.com>
Signed-off-by: Vaishnav Sabari Girish <vaishnav.sabari.girish@gmail.com>
Signed-off-by: Vaishnav Sabari Girish <vaishnav.sabari.girish@gmail.com>
There was a problem hiding this comment.
5 issues found across 10 files
Tip: cubic can generate docs of your entire codebase and keep them up to date. Try it here.
Re-trigger cubic
- ns_http: Replaced `to_string_lossy()` with raw byte extraction (`to_bytes().to_vec()`) for POST payloads to prevent the silent corruption of non-UTF-8 and binary data. - ns_http: Added explicit UTF-8 validation for GET response bodies, correctly returning `NsError::StringInvalidUtf8` upon failure. - ns_http: Updated null pointer validation in POST requests to return `NsError::InvalidInput` instead of a generic error. - ns_http: Also added bot-check bypass for sites protected by bots - build: Refactored the Makefile `uninstall` target to dynamically sync with `LIBS_TO_INSTALL` (using `addprefix` and `notdir`), fixing the bug where local build caches were targeted instead of system directories. - examples: Fixed capitalization typo in `18_http.c` console output. Signed-off-by: Vaishnav Sabari Girish <vaishnav.sabari.girish@gmail.com>
There was a problem hiding this comment.
2 issues found across 4 files (changes from recent commits).
Reply with feedback, questions, or to request a fix.
Re-trigger cubic
…ling - ns_http: Extracted duplicated `reqwest` client configuration into a single `build_default_client()` helper to prevent config drift between GET and POST requests. - ns_http: Updated error mapping in `ns_http_get` response text parsing to return the generic `NsError::Any` instead of `NsError::StringInvalidUtf8`. Signed-off-by: Vaishnav Sabari Girish <vaishnav.sabari.girish@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Implement memory-safe synchronous HTTP client
Introduces the
ns_httpmodule, wrapping Rust'sreqwestcrate to providea modern, synchronous HTTP API to C without the complexity and callback
management of
libcurl.Key additions:
ns_http_getandns_http_postfor standard web requests.ns_http_responsestruct to cleanly capture HTTP status codes andpack the response body directly into memory-safe SSO
ns_stringstructs.ns_autohttpmacro, leveraging the GCC/Clang cleanupattribute to provide RAII, automatically freeing HTTP response buffers
when they fall out of scope.
18_http.cexample demonstrating fetchingdata and pushing JSON payloads.
ns_httpcrate in the workspace and addedreqwestdependency.Summary by cubic
Adds a new
ns_httpmodule with a simple, memory-safe synchronous HTTP client for C. Supports GET/POST with RAII cleanup; POST is binary‑safe and GET/POST now share a unified client configuration.New Features
ns_httpcrate using blockingreqwestwith a browser-like User-Agent.ns_http_getandns_http_post; results vians_http_response(status +ns_stringbody).ns_autohttpmacro for auto-free; headerinclude/ns_http.h; exampleexamples/18_http.c; Makefile links-lns_http.Bug Fixes
NsError::InvalidInput.NsError::Any.uninstallusesLIBS_TO_INSTALLto remove all installed libs.Written for commit 0323427. Summary will update on new commits.